package com.bwie.myannotationtest.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.Window;

import com.bwie.myannotationtest.utils.ShareprefreceUtils;
import com.bwie.myannotationtest.utils.ToastUtils;

/**
 * Created by Administrator on 2016/7/8.
 */
public abstract class BaseActivity extends FragmentActivity {
    @Override
    public void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 加载布局
        setContentView(getLayout());

        // 找控件
        findView();
        //设置数据
        setData();
        // 设置监听
        setListener();
    }

    //获取要加载的布局
    public abstract int getLayout();

    //找控件
    public abstract void findView();

    //设置数据
    public abstract void setData();

    //设置监听
    public abstract void setListener();

    /*
     * 弹出吐司
     */
    public void showToast(String text) {
        if (TextUtils.isEmpty(text))
            return;
        ToastUtils.getToast(text);
    }

    /*
     * 获取对话框dialog对象
     */
    public AlertDialog getDialog(Context context, String title, String message,
                                 String positive, String negative,
                                 DialogInterface.OnClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setIcon(android.R.drawable.ic_dialog_info);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setPositiveButton(positive, listener);
        if (!TextUtils.isEmpty(negative)) {
            builder.setNegativeButton(negative, null);
        }
        AlertDialog dialog = builder.create();
        return dialog;
    }

    /*
     * 判断登录状态
     */
    public boolean isLogin(){
        return !TextUtils.isEmpty(ShareprefreceUtils.readfromExternl("uid",""));
    }

}
